Skip to content

Cache PackDescriptors#1239

Merged
lroberts36 merged 34 commits into
developfrom
lroberts36/cache-pack-descriptors
Jun 25, 2025
Merged

Cache PackDescriptors#1239
lroberts36 merged 34 commits into
developfrom
lroberts36/cache-pack-descriptors

Conversation

@lroberts36
Copy link
Copy Markdown
Collaborator

@lroberts36 lroberts36 commented Apr 8, 2025

PR Summary

PackDescriptors created using Mesh, MeshBlockData, and MeshData, MeshBlock, and StateDescriptor are automatically cached in the StateDesciptor. Additionally, the interface to MakePackDescriptor is generalized to work in all cases for StateDescriptor, Mesh, MeshBlockData, MeshBlock, and MeshData arguments. There is also a relatively simple mechanism for adding cacheing to downstream MakePackDescriptor functions that define their own selector for choosing fields to include in a PackDescriptor. This has been tested downstream with Riot.

PR Checklist

  • Code passes cpplint
  • New features are documented.
  • Adds a test for any bugs fixed. Adds tests for new features.
  • Code is formatted
  • Changes are summarized in CHANGELOG.md
  • Change is breaking (API, behavior, ...)
    • Change is additionally added to CHANGELOG.md in the breaking section
    • PR is marked as breaking
    • Short summary API changes at the top of the PR (plus optionally with an automated update/fix script)
  • CI has been triggered on Darwin for performance regression tests.
  • Docs build
  • (@lanl.gov employees) Update copyright on changed files

// surprisingly, this seems to be almost free
if (num_iter > 0) {
Kokkos::atomic_increment(&hist(num_iter - N_min));
Kokkos::atomic_inc(&hist(num_iter - N_min));
Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nothing to do with this PR, just removes a compiler warning.

@lroberts36 lroberts36 requested review from Yurlungur and pdmullen April 8, 2025 21:36
@lroberts36 lroberts36 changed the title WIP: Cache PackDescriptors Cache PackDescriptors Apr 8, 2025
Copy link
Copy Markdown
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like caching being automatic, but I don't think I love using a string. I feel like that could re-introduce performance hits from using string processing. I assume it's tied to meshblocks and mesh because you're imagining different block lists?

Would there be some way to cache the arguments to the pack instead?

@lroberts36
Copy link
Copy Markdown
Collaborator Author

lroberts36 commented Apr 9, 2025

@Yurlungur:

I like caching being automatic, but I don't think I love using a string. I feel like that could re-introduce performance hits from using string processing. I assume it's tied to meshblocks and mesh because you're imagining different block lists?

It is only tied to the Mesh. This is probably the most natural place to stash PackDescriptors, since a constructed Mesh object is guaranteed (?) to have a resolved StateDescriptor object. There are overloads for MakePackDescriptor with MeshData and MeshBlockData just for convenience.

Would there be some way to cache the arguments to the pack instead?

Yes, we could make the key be a tuple containing vector of strings, a vector of bools, a vector of Metadata, and a set of PDOpt. This would necessitate a second cache for packs created with UId_ts though.

@Yurlungur
Copy link
Copy Markdown
Collaborator

It is only tied to the Mesh. This is probably the most natural place to stash PackDescriptors, since a constructed Mesh object is guaranteed (?) to have a resolved StateDescriptor object. There are overloads for MakePackDescriptor with MeshData and MeshBlockData just for convenience.

👍 got it.

we could make the key be a tuple containing vector of strings, a vector of bools, a vector of Metadata, and a set of PDOpt. This would necessitate a second cache for packs created with UId_ts though.

I would strongly prefer to avoid using a string for caching. But I'm willing to be overruled.

@lroberts36
Copy link
Copy Markdown
Collaborator Author

I would strongly prefer to avoid using a string for caching. But I'm willing to be overruled.

Sure, it is easy enough to switch to a different key.

@lroberts36 lroberts36 changed the base branch from lroberts36/refactor-pack-code to develop April 9, 2025 22:14
@lroberts36
Copy link
Copy Markdown
Collaborator Author

@Yurlungur:

I like caching being automatic, but I don't think I love using a string. I feel like that could re-introduce performance hits from using string processing. I assume it's tied to meshblocks and mesh because you're imagining different block lists?

It is only tied to the Mesh. This is probably the most natural place to stash PackDescriptors, since a constructed Mesh object is guaranteed (?) to have a resolved StateDescriptor object.

It turned out to be cleaner to just put the cache in the StateDescriptor itself.

Copy link
Copy Markdown
Collaborator

@Yurlungur Yurlungur left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

Comment thread src/pack/make_pack_descriptor.cpp Outdated
Comment thread src/utils/hash.hpp
@Yurlungur Yurlungur requested review from pgrete and removed request for pgrete June 5, 2025 16:54
Copy link
Copy Markdown
Collaborator

@pgrete pgrete left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks like a nice cleanup with increased functionality (even though we're not using SparsePacks yet).

I only have some clarifying comments/questions.

Comment thread CHANGELOG.md Outdated
Comment thread doc/sphinx/src/sparse_packs.rst Outdated
Comment thread src/mesh/mesh.hpp
Comment on lines -243 to +246
using comm_buf_map_t =
std::unordered_map<channel_key_t, comm_buf_t, tuple_hash<channel_key_t>>;
using comm_buf_map_t = std::unordered_map<channel_key_t, comm_buf_t>;
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change?
And if I didn't miss anything, neither that type nor boundary_comm_map are touched otherwise in this PR, so why is this still working?

const std::vector<bool> &use_regex,
const std::vector<MetadataFlag> &flags,
const std::set<PDOpt> &options) {
const std::string cache_label{"normal"};
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are these labels, i.e., "normal" and "uid" only used internally?
Is there other code (beyond this PR) that depends on those labels?
Given that I'm not familiar with sparse packs, these question may be trivial/make no sense.
If they do make sense, then maybe one or two lines of documentation might be useful explaining the choice/intent.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, they are entirely internal and no downstream user (and most Parthenon developers) should never have to worry about them. It is just a way to allow different methods of creating PackDescriptors to have their own caches.

Comment thread src/pack/make_pack_descriptor.cpp Outdated
Comment thread src/pack/make_pack_descriptor.cpp
Comment thread src/pack/make_pack_descriptor.cpp Outdated
Comment thread src/utils/hash.hpp

namespace parthenon {

// A hash struct that can be used as a template class in
Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I trust that the updates here work as expected (probably refactored 1:1 from boost, aren't they?)

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't steal them from Boost, but they seem to work correctly. That being said, I haven't checked their performance at all.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

They should give the same results as the code that we previously had in there though.

@lroberts36 lroberts36 enabled auto-merge June 18, 2025 21:13
@Yurlungur Yurlungur disabled auto-merge June 20, 2025 19:59
@Yurlungur Yurlungur enabled auto-merge June 20, 2025 19:59
@Yurlungur
Copy link
Copy Markdown
Collaborator

Check that this MR merges

@lroberts36 lroberts36 disabled auto-merge June 24, 2025 23:22
@lroberts36 lroberts36 enabled auto-merge June 24, 2025 23:22
@lroberts36 lroberts36 merged commit 094622c into develop Jun 25, 2025
34 of 37 checks passed
@lroberts36 lroberts36 deleted the lroberts36/cache-pack-descriptors branch June 25, 2025 01:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants